package com.koron.common.web.controller.message;

import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.business.message.bean.po.MessageHistoryPo;
import com.koron.common.core.business.message.bean.query.MessageHistoryQuery;
import com.koron.common.core.business.message.service.MessageHistoryService;
import com.koron.common.core.config.ThreadLocalContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 消息发送历史表(MessageHistory)表控制层
 *
 * @author zhouj
 * @since 2022-03-16 14:13:22
 */
@Api(tags = "消息发送历史表(MessageHistory)")
@RestController
@RequestMapping("/messageHistory/")
public class MessageHistoryController {

    @Autowired
    private MessageHistoryService messageHistoryService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "新增或修改消息发送历史表")
    @PostMapping("insertOrUpdate")
    public Response<Integer> insertOrUpdate(@RequestBody MessageHistoryPo messageHistory) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), messageHistoryService, "insertOrUpdate", Integer.class, messageHistory));
    }

    @ApiOperation(value = "新增消息发送历史表")
    @PostMapping("insert")
    public Response<Integer> insert(@RequestBody MessageHistoryPo messageHistory) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), messageHistoryService, "insert", Integer.class, messageHistory));
    }

    @ApiOperation(value = "批量新增消息发送历史表")
    @PostMapping("insertBatch")
    public Response<Integer> insertBatch(@RequestBody List<MessageHistoryPo> messageHistoryList) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), messageHistoryService, "insertBatch", Integer.class, messageHistoryList));
    }

    @ApiOperation(value = "根据id更新消息发送历史表")
    @PutMapping("update")
    public Response<Integer> update(@RequestBody MessageHistoryPo messageHistory) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), messageHistoryService, "update", Integer.class, messageHistory));
    }

    @ApiOperation(value = "根据id删除消息发送历史表")
    @DeleteMapping("deleteById")
    public Response<Integer> deleteById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), messageHistoryService, "deleteById", Integer.class, id));
    }

    @ApiOperation(value = "根据id查询消息发送历史表")
    @GetMapping("queryById")
    public Response<MessageHistoryPo> queryById(String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), messageHistoryService, "queryById", MessageHistoryPo.class, id));
    }

    @ApiOperation(value = "不分页查询消息发送历史表列表")
    @GetMapping("queryList")
    public Response<List> queryList(MessageHistoryQuery messageHistoryQuery) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), messageHistoryService, "queryList", List.class, messageHistoryQuery));
    }

    @ApiOperation(value = "分页查询消息发送历史表列表")
    @GetMapping("queryPageList")
    public Response<PageInfo> queryPageList(MessageHistoryQuery messageHistoryQuery, PageQuery pageQuery) {
        Assert.isTrue(StringUtils.isNotEmpty(messageHistoryQuery.getAppMark()),"租户不能为空");
        return Response.ok(ADOConnection.runTask(messageHistoryQuery.getAppMark(), messageHistoryService, "queryPageList", PageInfo.class, messageHistoryQuery, pageQuery));
    }

}
